// 这是关于音乐细节的网络请求
import { request } from './request'
import { formatDate } from 'assets/common/tool'
// 根据歌单id,获取歌单所含的歌曲
export function _getMusicListDetail (id) {
  return request({
    url: 'playlist/detail',
    params: {
      id: id
    }
  })
}
// 获取歌曲地址
export function _getMusicUrl (id) {
  return request({
    url: '/song/url',
    params: {
      id: id
    }
  })
}

// 歌曲评论
export function _musicRecommends (id, limit) {
  return request({
    url: '/comment/music',
    params: {
      id: id,
      limit: limit
    }
  })
}

// 获取歌词
export function _getLyric (id) {
  return request({
    url: '/lyric',
    params: {
      id: id
    }
  })
}

// 发表评论
export function _pushCommend (cookie, id, content) {
  return request({
    url: '/comment',
    params: {
      cookie: cookie,
      t: 1,
      type: 2,
      id: id,
      content: content
    }
  })
}

// 歌单的收藏
export function _getSub (id, limit) {
  return request({
    url: 'playlist/subscribers',
    params: {
      id: id,
      limit: limit
    }
  })
}

// 歌单评论信息
export function _getRecommends (id, limit) {
  return request({
    url: '/comment/playlist',
    params: {
      id: id,
      limit: limit
    }
  })
}

// 获取歌单歌曲详情
export function _getSongsDetail (arr) {
  return request({
    url: '/song/detail',
    params: {
      ids: arr
    }
  })
}
// 提取音乐的重要信息
export class SongDetail {
  constructor (songs) {
    this.id = songs[0].id
    this.name = songs[0].name
    this.album = songs[0].al.name
    this.artist = songs[0].ar[0].name
    this.pic = songs[0].al.picUrl
    this.time = formatDate(new Date(songs[0].dt), 'mm:ss')
  }
}

// 提取专辑的重要信息
export class AlbumDetail {
  constructor (album) {
    this.name = album.name
    this.description = album.description
    this.pic = album.picUrl
    this.company = album.company
    this.artist = album.artists[0].name
    this.publishTime = album.publishTime
  }
}
// 提取专辑所包含的音乐的信息
export class AlbumSongDetail {
  constructor (songs) {
    this.id = songs.id
    this.name = songs.name
    this.album = songs.al.name
    this.artist = songs.ar[0].name
    this.pic = songs.al.picUrl
    this.time = formatDate(new Date(songs.dt), 'mm:ss')
  }
}
export class BaseInfo {
  constructor (playlist) {
    this.pic = playlist.coverImgUrl
    this.title = playlist.description
    this.name = playlist.name
    this.shareCount = playlist.shareCount
    // 是否收藏
    this.subscribed = playlist.subscribed
    // 收藏的数量
    this.subscribedCount = playlist.subscribedCount
    this.playCount = playlist.playCount
    this.trackCount = playlist.trackCount
    this.tags = playlist.tags[0]
    this.createTime = playlist.createTime
  }
}
// 获取新专辑上架
export function _getNewest () {
  return request({
    url: '/album/newest'
  })
}
// 根据专辑id获取专辑中的歌曲
export function _getNewestDetail (id) {
  return request({
    url: '/album',
    params: {
      id: id
    }
  })
}
// 专辑评论
export function _getAlbumrecommends (id) {
  return request({
    url: '/comment/album',
    params: {
      id: id
    }
  })
}
// 收藏歌单
export function _collMusic (id, t) {
  return request({
    url: '/playlist/subscribe',
    params: {
      t: t,
      id: id
    }
  })
}
